<%@page language="java" contentType="text/html; charset=utf-8"%>
<%@include file="/commons/inc.jsp" %>


<h3 id="navTitleId">个人史</h3>
<script>
function show(){
	var ifdrink = '<s:property value='personal.drink'/>';
	if(ifdrink==2){
		$('personal.drinkage').disabled=false;
		for(var i=1;i<=4;i++){
			$('dt'+i).disabled=false;
			$('df'+i).disabled=false;
			$('da'+i).disabled=false;
		}
		
		var type = '<s:property value='personal.drinktype'/>';
		var freq = '<s:property value='personal.drinkfrequency'/>';
		var amount = '<s:property value='personal.drinkamount'/>';

		if(type!=null && freq!=null && amount!=null){
			type = type.split(",");
			freq = freq.split(",");	
			amount = amount.split(",");
			for(var i=0;i<type.length;i++){
				var n = i+1;
				if(type[i].trim()==1){
					$('dt'+n).checked = true;	
					$('dt'+n).value = 1;		
					$('df'+n).value = freq[i].trim();	 		
					$('da'+n).value = amount[i].trim(); 	
				}else{
					$('dt'+n).checked = false;	
					$('dt'+n).value = 0;
					$('df'+n).value = "";	
					$('da'+n).value = ""; 
				}
			}
		}
	}else{
		$('personal.drinkage').value="";
		$('personal.drinkage').disabled=true;
		
		for(var i=1;i<=4;i++){
			$('dt'+i).checked = false;
			$('dt'+i).value = 0;
			$('dt'+i).disabled=true;
			
			$('df'+i).value="";
			$('df'+i).disabled=true;
			$('da'+i).value="";
			$('da'+i).disabled=true;	
		}
	}
}

function showtips(tips,flag){ 
	var tip=document.getElementById(tips);
	if(tip.style.display=="none"){ 
	        tip.style.display="inline";
	        //my_tips.style.left=event.clientX+10; 
	        //my_tips.style.top=event.clientY+10; 
	}else{ 
	      tip.style.display="none"; 
	} 
}
</script>

<body id="body">

<%@include file="/commons/showmessage.jsp" %>

<form name="personalform" id="personalform" method="post" action="${contextPath}/personal/personal.action?method=saveEditPersonal">
	<s:hidden name="personal.patientid" id="personal.patientid"></s:hidden>
	<s:hidden name="personal.personalid" id="personal.personalid"></s:hidden>
	<s:hidden name="personal.drinktype" id="personal.drinktype"></s:hidden>
	<s:hidden name="personal.drinkfrequency" id="personal.drinkfrequency"></s:hidden>
	<s:hidden name="personal.drinkamount" id="personal.drinkamount"></s:hidden>
	<s:hidden name="patientid" id="patientid"></s:hidden>
	
	<table border="0" cellspacing="1" cellpadding="0" class="formTable" width="100%" >
		<tr>
			<td class="form-td"><label class="label">学历:</label></td>
			<td class="form-td"> 
				<select name="personal.education" id="personal.education" style="width:100px;">
					<option value="0" <s:if test="personal.education == 0">selected</s:if>>请选择</option>
					<option value="1" <s:if test="personal.education == 1">selected</s:if>>大专及大专以上</option>
					<option value="2" <s:if test="personal.education == 2">selected</s:if>>高中或中专</option>
					<option value="3" <s:if test="personal.education == 3">selected</s:if>>初中</option>
					<option value="4" <s:if test="personal.education == 4">selected</s:if>>小学</option>
					<option value="5" <s:if test="personal.education == 5">selected</s:if>>文盲半文盲</option>
					<option value="6" <s:if test="personal.education == 6">selected</s:if>>不详</option>
				</select></td>
			 
			<td class="form-td"><label class="label">家庭人均月收入:</label></td>
			<td class="form-td" colspan="2"><select name="personal.income" id="personal.income">
					<option value="0" <s:if test="personal.income == 0">selected</s:if>>请选择</option>
					<option value="1" <s:if test="personal.income == 1">selected</s:if>><500元</option>
					<option value="2" <s:if test="personal.income == 2">selected</s:if>>500-1000元</option>
					<option value="3" <s:if test="personal.income == 3">selected</s:if>>1000-2000元</option>
					<option value="4" <s:if test="personal.income == 4">selected</s:if>>2000-5000元</option>
					<option value="5" <s:if test="personal.income == 5">selected</s:if>>5000-10000元</option>
					<option value="6" <s:if test="personal.income == 6">selected</s:if>>>100000元</option>
					<option value="7" <s:if test="personal.income == 7">selected</s:if>>不详</option>
				</select></td>
		</tr>
		<tr>
			<td class="form-td"><label class="label">婚姻状况:</label></td>
			<td class="form-td" colspan="4">
				<select name="personal.marriage" id="personal.marriage" style="width:100px;">
					<option value="0" <s:if test="personal.marriage == 0">selected</s:if> >请选择</option>
					<option value="1" <s:if test="personal.marriage == 1">selected</s:if> >已婚</option>
					<option value="2" <s:if test="personal.marriage == 2">selected</s:if> >未婚</option>
					<option value="3" <s:if test="personal.marriage == 3">selected</s:if> >再婚</option>
					<option value="4" <s:if test="personal.marriage == 4">selected</s:if> >离异</option>
					<option value="5" <s:if test="personal.marriage == 5">selected</s:if> >丧偶</option>
				</select></td>
		</tr>
		<tr>
			<td class="form-td"><label class="label">社会经历:</label></td>
			<td class="form-td"><label class="label">出生地:</label></td>
			<td class="form-td"><input type="text" name="personal.birthplace" id="personal.birthplace" value="${personal.birthplace}"/></td>
			<td class="form-td"><label class="label">出生体重:</label></td>
			<td class="form-td"><input type="text" name="personal.birthweight" id="personal.birthweight" value="${personal.birthweight}" size="2"/>kg</td>
		</tr>
		<tr>
			<td class="form-td"></td>
			<td class="form-td"><label class="label">长期居留地:</label></td>
			<td class="form-td"><input type="text" name="personal.liveplace" id="personal.liveplace" value="${personal.liveplace}"/></td>
		  	<td class="form-td"><label class="label">居留时间:</label></td>
			<td class="form-td"><input type="text" name="personal.livelong" id="personal.livelong" value="${personal.livelong}" size="2"/>年</td>
		</tr>

		<tr>
			<td class="form-td"><label class="label">药物过敏史:</label></td>
			<td class="form-td">
				<select name="personal.drugallergy" id="personal.drugallergy" onchange="javascript:drugType();">
					<option value="0" <s:if test="personal.drugallergy == 0">selected</s:if>>请选择</option>
					<option value="1" <s:if test="personal.drugallergy == 1">selected</s:if>>无</option>
					<option value="2" <s:if test="personal.drugallergy == 2">selected</s:if>>有</option>
					<option value="3" <s:if test="personal.drugallergy == 3">selected</s:if>>不详</option>
				</select></td>
			<td class="form-td" colspan="3"><label class="label">过敏药物:</label> 
			 <input type="text" name="personal.drug" id="personal.drug" <s:if test="personal.drugallergy==null ||personal.drugallergy==0 ">disabled="disabled"</s:if> value="${personal.drug}"/></td>
		</tr>
		
		<tr>
			<td class="form-td"><label class="label">食物过敏史:</label></td>
			<td class="form-td">
				<select name="personal.foodallergy" id="personal.foodallergy" onchange="javascript:foodType();">
					<option value="0" <s:if test="personal.foodallergy == 0">selected</s:if>>请选择</option>
					<option value="1" <s:if test="personal.foodallergy == 1">selected</s:if>>无</option>
					<option value="2" <s:if test="personal.foodallergy == 2">selected</s:if>>有</option>
					<option value="3" <s:if test="personal.foodallergy == 3">selected</s:if>>不详</option>
				</select></td>
			<td class="form-td" colspan="3"><label class="label">过敏食物:</label> 
			 <input type="text" name="personal.food" id="personal.food" <s:if test="personal.foodallergy==null || personal.foodallergy==0">disabled="disabled"</s:if> value="${personal.food}"/></td>
		</tr>
		</table>
		
		<p></p>
		<table border="0" cellspacing="1" cellpadding="0" class="formTable" width="100%" >
		<tr>
			<td class="form-td"><label class="label">饮酒情况:</label></td>
			<td class="form-td" colspan="2"><label class="label">饮酒:</label>
			<br><a onclick="showtips('1',1);">【说明】
			<br><img id='1' style="display:none" src="../images/tips/1.png" />
			</a></td>
			<td class="form-td" colspan="2">
				<select name="personal.drink" id="personal.drink" onchange="javascript:drinkType();" >
					<option value="0" <s:if test="personal.drink == 0">selected</s:if>>请选择</option>
					<option value="1" <s:if test="personal.drink == 1">selected</s:if>>否</option>
					<option value="2" <s:if test="personal.drink == 2">selected</s:if>>是</option>
				</select></td>
			<td class="form-td" colspan="2"><label class="label">开始饮酒的年龄:</label></td>
			<td class="form-td" colspan="2"><input type="text" name="personal.drinkage" id="personal.drinkage" value="${personal.drinkage}" size="2"/>岁</td>
		</tr>
		
		<tr>
			<td class="form-td"></td>
			<td class="form-td" colspan="2"><label class="label">戒酒:</label></td>
			<td class="form-td" colspan="2">
				<select name="personal.stopdrink" id="personal.stopdrink" onchange="javascript:stopDrink();">
					<option value="0" <s:if test="personal.stopdrink == 0">selected</s:if>>请选择</option>
					<option value="1" <s:if test="personal.stopdrink == 1">selected</s:if>>否</option>
					<option value="2" <s:if test="personal.stopdrink == 2">selected</s:if>>是</option>
				</select></td>
			<td class="form-td" colspan="2"><label class="label">戒酒时间:</label></td>		
			<td class="form-td" colspan="2"><input type="text" name="personal.stopdrinktime" id="personal.stopdrinktime" <s:if test="personal.stopdrink==null || personal.stopdrink==0">disabled="disabled"</s:if> value="${personal.stopdrinktime}" size="2"/>年</td>		
		</tr>
		
		<tr>
			<td class="form-td"></td>
			<td class="form-td" colspan="2"><label class="label">饮酒的种类及数量:</label></td>
			<td class="form-td"><input type="checkbox" name="dt1" id="dt1" value="1" onclick="javascript:typeSel(1);"/>
				<font style="vertical-align:bottom;">白酒</font></td>
			<td class="form-td">
				<input type="text" name="df1" id="df1" size="2"/>次/周 <input type="text" name="da1" id="da1" size="2"/>两/次 </td>
			<td class="form-td"><input type="checkbox" name="dt2" id="dt2" value="1" onclick="javascript:typeSel(2);"/>
				<font style="vertical-align:bottom;">黄酒</font></td>
			<td class="form-td" colspan="2">
				<input type="text" name="df2" id="df2" size="2"/>次/周 <input type="text" name="da2" id="da2" size="2"/>两/次</td>
		</tr>
		<tr>
			<td class="form-td" colspan="3"></td>
			<td class="form-td"><input type="checkbox" name="dt3" id="dt3" value="1" onclick="javascript:typeSel(3);"/>
				<font style="vertical-align:bottom;">红酒</font></td>
			<td class="form-td"><input type="text" name="df3" id="df3" size="2"/>次/周 
					<input type="text" name="da3" id="da3" size="2"/>两/次 </td>
			<td class="form-td"><input type="checkbox" name="dt4" id="dt4" value="1" onclick="javascript:typeSel(4);"/>
				<font style="vertical-align:bottom;">啤酒</font></td>
			<td class="form-td" colspan="2">
				<input type="text" name="df4" id="df4" size="2"/>次/周<input type="text" name="da4" id="da4" size="2"/>瓶/次<script>show()</script></td>
		</tr>
	 </table>
	 
	 <p></p>
	 <table border="0" cellspacing="1" cellpadding="0" class="formTable" width="100%" >
		<tr>
			<td class="form-td"><label class="label">吸烟情况</label></td>
			<td class="form-td"><label class="label">吸烟:</label>
			<br><a onclick="showtips('2',1);">【说明】
			<br><img id='2' style="display:none" src="../images/tips/2.png" />
			</a></td>
			<td class="form-td">
				<select name="personal.smoke" id="personal.smoke" onchange="javascript:smokeType();">
					<option value="0" <s:if test="personal.smoke == 0">selected</s:if>>请选择</option>
					<option value="1" <s:if test="personal.smoke == 1">selected</s:if>>否</option>
					<option value="2" <s:if test="personal.smoke == 2">selected</s:if>>是</option>
				</select></td>
			<td class="form-td"><label class="label">每日吸烟支数:</label></td>
			<td class="form-td"><input type="text" name="personal.smokeamount" onchange="javascript:xiyan();" id="personal.smokeamount" <s:if test="personal.smoke==null || personal.smoke==0">disabled="disabled"</s:if> value="${personal.smokeamount}" size="2"/>支</td>
			<td class="form-td"><label class="label">吸烟年数:</label></td>
			<td class="form-td"><input type="text" name="personal.smokelast" onchange="javascript:xiyan();" id="personal.smokelast" <s:if test="personal.smoke==null || personal.smoke==0">disabled="disabled"</s:if> value="${personal.smokelast}" size="2"/>年</td>
			<td class="form-td"><label class="label">吸烟指数:</label></td>
			<td class="form-td"><input type="text" name="personal.smokeexpo" readonly="readonly" id="personal.smokeexpo" <s:if test="personal.smoke==null || personal.smoke==0">disabled="disabled"</s:if> value="${personal.smokeexpo}" size="2"/></td>	
		 </tr>
		 
		 <tr>
		 	<td class="form-td"></td>
			<td class="form-td"><label class="label">戒烟:</label></td>
			<td class="form-td">
				<select name="personal.stopsmoke" id="personal.stopsmoke" onchange="javascript:stopSmoke();">
					<option value="0" <s:if test="personal.stopsmoke == 0">selected</s:if>>请选择</option>
					<option value="1" <s:if test="personal.stopsmoke == 1">selected</s:if>>否</option>
					<option value="2" <s:if test="personal.stopsmoke == 2">selected</s:if>>是</option>
				</select></td>
			<td class="form-td"><label class="label">戒烟年数:</label></td>
			<td class="form-td"><input type="text" name="personal.stopsmokelast" id="personal.stopsmokelast" <s:if test="personal.stopsmoke==null || personal.stopsmoke==0">disabled="disabled"</s:if> value="${personal.stopsmokelast}" size="2"/>年</td>
			<td class="form-td"><label class="label">周围环境中经常有人吸烟:</label></td>
			<td class="form-td" colspan="3"><select name="personal.aroundsmoke" id="personal.aroundsmoke">
					<option value="0" <s:if test="personal.aroundsmoke == 0">selected</s:if>>请选择</option>
					<option value="1" <s:if test="personal.aroundsmoke == 1">selected</s:if>>是</option>
					<option value="2" <s:if test="personal.aroundsmoke == 2">selected</s:if>>否</option>
				</select></td>		
		</tr>
		<tr>
			<td align="center" colspan="7"> 
			<input type="reset" value="重置"> 
		    <input type="button" onclick="saveEdit('save');" value="保存">
		    <input type="button" onclick="javascript:back();"value="返回列表"></td>
		</tr>
	</table>
</form>

<%@include file="/commons/tableSel.jsp" %>

</body>
<style type="text/css">
body {
	height: 100%;
	width: 100%;
}
</style>

<script>
function back(){
	location.href="${contextPath}/patient/patient.action?method=query";
}
function saveEdit(type){
	if(type=='refresh'){
		location.reload();
	}else if(type=='save'){
		if(!Validator.Validate($('personalform'),3)){
			return;
		}	
		var tt = new Array();
		var freq = new Array();
		var amount = new Array();
		for(var i=1;i<=4;i++){
			tt[i-1] = ($('dt'+i).value=="")? 0:$('dt'+i).value;
			freq[i-1] = ($('df'+i).value=="")? 0:$('df'+i).value;
			amount[i-1] = ($('da'+i).value=="")? 0:$('da'+i).value;
		}
		$('personal.drinktype').value = tt.join(",");
		$('personal.drinkfrequency').value = freq.join(",");
		$('personal.drinkamount').value = amount.join(",");
		$('personalform').submit();
	}
}
function typeSel(id){
	if(!$('dt'+id).checked){
		$('dt'+id).value="0";
		$('df'+id).value="";
		$('da'+id).value="";
	}else{
		$('dt'+id).value="1";
	}
}
function drugType(){
	var c = $('personal.drugallergy').value;
	if(c==1){
		$('personal.drug').disabled=true;
		$('personal.drug').value="";
	}else{
		$('personal.drug').disabled=false;
	}
}
function foodType(){
	var c = $('personal.foodallergy').value;
	if(c==1){
		$('personal.food').disabled=true;
		$('personal.food').value="";
	}else{
		$('personal.food').disabled=false;
	}
}
function drinkType(){
	var c = $('personal.drink').value;
	if(c==2){ //是
		$('personal.drinkage').disabled=false;
		for(var i=1;i<=4;i++){
			$('dt'+i).disabled=false;
			$('df'+i).disabled=false;
			$('da'+i).disabled=false;
		}
	}else{//否
		$('personal.drinkage').value="";
		$('personal.drinkage').disabled=true;
		
		for(var i=1;i<=4;i++){
			$('dt'+i).checked = false;
			$('dt'+i).value = 0;
			$('dt'+i).disabled=true;
			
			$('df'+i).value="";
			$('df'+i).disabled=true;
			$('da'+i).value="";
			$('da'+i).disabled=true;	
		}
	}
}
function smokeType(){
	var c = $('personal.smoke').value;
	if(c==1){
		$('personal.smokeamount').disabled=true;
		$('personal.smokelast').disabled=true;
		$('personal.smokeexpo').disabled=true;
		$('personal.smokeamount').value="";
		$('personal.smokelast').value="";
		$('personal.smokeexpo').value="";
	}else{
		$('personal.smokeamount').disabled=false;
		$('personal.smokelast').disabled=false;
		$('personal.smokeexpo').disabled=false;
	}
}
function stopDrink(){
	var c = $('personal.stopdrink').value;
	if(c==1){
		$('personal.stopdrinktime').disabled=true;
		$('personal.stopdrinktime').value="";
	}else if(c==2){
		$('personal.stopdrinktime').disabled=false;
	}
}
function stopSmoke(){
	var c = $('personal.stopsmoke').value;
	if(c==1){
		$('personal.stopsmokelast').disabled=true;
		$('personal.stopsmokelast').value="";
	}else{
		$('personal.stopsmokelast').disabled=false;
	}
}
function xiyan(){
	var a = $('personal.smokeamount').value;
	var b = $('personal.smokelast').value;
	if(a!=null && b!=null){
		$('personal.smokeexpo').value = a*b;
	}
}
</script>